//
//  UWGameBoard.h
//  Urban Words
//
//  Created by Tim Brandin on 2011-12-01.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import "UWGame.h"
#import "BoardPrefs.h"
#import "UWBrick.h"
#import "PTPusherEvent.h"

@protocol TapDetectingViewDelegate;

CGPoint midpointBetweenTouches(CGPoint a, CGPoint b);

@interface UWGameBoard : UIView {
    
    CGContextRef ctx;
    
    id <TapDetectingViewDelegate> delegate;
    
    UWGame *game;
    
    UWBrick *bricks[BRICK_COUNT*BRICK_COUNT];
    unichar letters[BRICK_COUNT*BRICK_COUNT];
    
    // Touch detection
    CGPoint tapLocation;
    BOOL multipleTouches;
    BOOL twoFingerTapIsPossible;
    
    SystemSoundID shuffle;
    SystemSoundID place;
    SystemSoundID fail;
    SystemSoundID success;
    SystemSoundID turn;
}

@property (nonatomic, assign) id <TapDetectingViewDelegate> delegate;

@property (nonatomic, retain) UWGame *game;

@property SystemSoundID shuffle;
@property SystemSoundID place;
@property SystemSoundID fail;
@property SystemSoundID success;
@property SystemSoundID turn;

- (SystemSoundID)createSoundID:(NSString *)src;

- (void)handleSingleTap;
- (void)handleDoubleTap;
- (void)handleTwoFingerTap;
- (UWBrick *)getBrickAt:(int)pos;
- (void)setLetter:(NSString *)letter atPos:(int)position;
- (void)setLetter:(NSString *)letter atPos:(int)position withState:(BRICK_STATE)state;
- (void)clearLetterAtPos:(int)position;

- (void)paintBrick:(int)id X:(int)x Y:(int)y Rect:(CGRect)rect;
- (void)paintStarBrick:(int)id X:(int)x Y:(int)y Rect:(CGRect)rect;

- (CGRect)putWords:(PTPusherEvent *)words;
- (void)putWord:(NSString *)word atPos:(int)id atDirection:(int)h withState:(BRICK_STATE)state;

@end



@protocol TapDetectingViewDelegate <NSObject>

@optional
- (void)boardView:(UWGameBoard *)board gotSingleTapAtPoint:(CGPoint)tapPoint;
- (void)boardView:(UWGameBoard *)board gotDoubleTapAtPoint:(CGPoint)tapPoint;
- (void)boardView:(UWGameBoard *)board gotTwoFingerTapAtPoint:(CGPoint)tapPoint;
- (UIView *)boardView:(UWGameBoard *)board hitTest:(CGPoint)point withEvent:(UIEvent *)event;

@end
